package com.stockz.equity.charting.painter.screen;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.stockz.equity.charting.display.screen.AbstractDisplayableScreenConfiguration;
import com.stockz.equity.charting.util.MathUtil;
import com.stockz.equity.charting.view.StockChartPanelState;
import com.stockz.equity.charting.view.StockChartView;
import com.stockz.equity.pattern.Painter;

@Component
public class ScreenMatchPainter implements Painter<AbstractDisplayableScreenConfiguration> {

	@Autowired
	private StockChartView stockChartView;
	
	@Override
	public void paint(Graphics2D g, AbstractDisplayableScreenConfiguration screen, Rectangle rectangle) {
		StockChartPanelState stockChartPanelState = stockChartView.getSelectedStockChart().getStockChartPanel().getStockChartPanelState();

		
		Color color = new Color(0,0,255,50);
		g.setColor(color);

		
		for(int index : screen.getMatches()){
			int x = MathUtil.fitX(rectangle.x, 
					stockChartPanelState.getTimeUnitSpace(), 
					stockChartPanelState.getEndIndex(), 
					index);
			
			g.fillRect(x, rectangle.y, stockChartPanelState.getTimeUnitSpace(), rectangle.height);
		}
		
	}
}
